package onlineclass.service;

import onlineclass.dao.OMajorMapper;
import onlineclass.dao.OUserMapper;
import onlineclass.entity.OMajor;
import onlineclass.entity.OUser;
import onlineclass.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

public class OMajorService {

    private static Logger Log = LoggerFactory.getLogger(OMajorService.class);
    public static final OMajorService INST = new OMajorService();
    public int add(OMajor oMajor){
        SqlSession s = MyBatisUtil.get();
        try {
            OMajorMapper mapper = s.getMapper(OMajorMapper.class);
            return mapper.add(oMajor);
        }  finally {
            MyBatisUtil.close(s);
        }
    }
    public int update(OMajor oMajor){
        SqlSession s = MyBatisUtil.get();
        try {
            OMajorMapper mapper = s.getMapper(OMajorMapper.class);
            return mapper.update(oMajor);
        }  finally {
            MyBatisUtil.close(s);
        }
    }
    public int del(long id){
        SqlSession s = MyBatisUtil.get();
        try {
            OMajorMapper mapper = s.getMapper(OMajorMapper.class);
            return mapper.del(id);
        }  finally {
            MyBatisUtil.close(s);
        }
    }
    public OMajor get(long id){
        SqlSession s = MyBatisUtil.get();
        try {
            OMajorMapper mapper = s.getMapper(OMajorMapper.class);
            return mapper.get(id);
        }  finally {
            MyBatisUtil.close(s);
        }
    }

    public List<OMajor> find(int pageNo, int pageSize, String name){
        SqlSession s = MyBatisUtil.get();
        try {
            OMajorMapper mapper = s.getMapper(OMajorMapper.class);
            return mapper.find(pageNo,pageSize,name);
        }  finally {
            MyBatisUtil.close(s);
        }
    }
}
